package com.zhao.integration.jms;

import javax.jms.Connection;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.stereotype.Component;

@Component
public class MessageSender extends Messager {
	private static final int SEND_NUMBER = 5;

	public void send(String queueName, Object obj) throws Exception {
		Connection connection = connection(connectionFactory());
		Session session = session(connection);
		try {
			MessageProducer messageProducer = messageProducer(session, destination(session, queueName));
			for (int i = 1; i <= SEND_NUMBER; i++) {
				TextMessage message = session.createTextMessage("呵呵" + i);
				// 发送消息到目的地方
				messageProducer.send(message);
			}
			session.commit();
			//		} catch (Exception e) {
			//			session.rollback();
		} finally {
			close(connection);
		}
	}
}